Voy a trabajar con la base de defunciones
OPERACIONES BÀSICAS
## # A tibble: 1 × 1
## Promedio
## <dbl>
## 1 15.8
## # A tibble: 1 × 2
## Promedio Dia_nac
## <dbl> <dbl>
## 1 15.8 16.8
## # A tibble: 32 × 2
## ent_regis Median
## <chr> <dbl>
## 1 01 16
## 2 02 16
## 3 03 16
## 4 04 15
## 5 05 16
## 6 06 16
## 7 07 15
## 8 08 16
## 9 09 16
## 10 10 16
## # … with 22 more rows
## # ℹ Use `print(n = ...)` to see more rows
Voy a relacionar las defunciones con la poblaciòn y la marginaciòn tambièn aprenderè a leer archivos excel y màs..
library(readxl)
IME_2020 <- read_excel("IME_2020.xls", skip = 3)
## New names:
## • `` -> `...16`
IME_2020<-IME_2020 %>%
filter(!is.na(CVE_ENT),
!is.na(POB_TOT))
generè un objeto que tiene las defunciones por entidad y al unirè a la poblaciòn y indicadores de marginaciòn
ent_def<-defunciones %>%
group_by(ent_regis) %>%
tally()
Lo harè a travès de una funciòn llamada “join” mi variable se llama ent_regis y de poblaciòn se llama CVE_ENT
def_final<-left_join(ent_def,IME_2020,by=c("ent_regis"="CVE_ENT"))
# agregar columnas
Con mutate voy a crear variables
def_final %>%
mutate(tasa_100=(n/POB_TOT)*100000) %>%
select(1,2,3,POB_TOT,tasa_100)
## # A tibble: 32 × 5
## ent_regis n NOM_ENT POB_TOT tasa_100
## <chr> <int> <chr> <dbl> <dbl>
## 1 01 6320 Aguascalientes 1425607 443.
## 2 02 20820 Baja California 3769020 552.
## 3 03 3984 Baja California Sur 798447 499.
## 4 04 4524 Campeche 928363 487.
## 5 05 16715 Coahuila de Zaragoza 3146771 531.
## 6 06 4917 Colima 731391 672.
## 7 07 26629 Chiapas 5543828 480.
## 8 08 24033 Chihuahua 3741869 642.
## 9 09 75648 Ciudad de México 9209944 821.
## 10 10 9256 Durango 1832650 505.
## # … with 22 more rows
## # ℹ Use `print(n = ...)` to see more rows
grafico <- def_final %>%
mutate(tasa_100=(n/POB_TOT)*100000) %>%
select(1,2,3,POB_TOT,tasa_100) %>%
ggplot()+
geom_col(aes(x=NOM_ENT,y=tasa_100,fill=NOM_ENT))
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
ggplotly(grafico)